let mongoose = require("./db");
const userSchema = mongoose.Schema({
  username: String,
  password: {
    type: String,
    default: "123456",
  },
  contacts: Array,
  role: mongoose.Types.ObjectId, //角色ID
  tid: {
    type: mongoose.Types.ObjectId, // 老师Id
    default: "",
  },
});
const userModel = mongoose.model("user", userSchema, "user");
//角色列表
let rolelist = mongoose.Schema({
  name: String,
  qid: [mongoose.Types.ObjectId],
});

let role = mongoose.model("role", rolelist);
//权限列表
let authoritylist = mongoose.Schema({
  name: String,
  pid: mongoose.Types.ObjectId,
  level: Number,
  titsrc: String,
  url: String,
  img: String,
});

let authority = mongoose.model("authority", authoritylist);




//-------------------------------------------------------------
//用户列表
let UserList=mongoose.Schema({
  petname:String,//昵称
  id:Number,//ID
  phone:Number,//手机号码
  avatar:String,//头像
  Realname:String,//真实姓名
  idno:Number,//身份证号
  sex:Boolean,//性别
  dateofbirth:Date,//出生日期
  homeaddress:String,//家庭住址
  brief:String,//简介
  height:Number,//身高
  weight:Number,//体重
  originorbirthplace:String,//籍贯
  nationid:{//民族
    type: mongoose.Types.ObjectId,
    ref: "nation",
  },
  educationid:{//文化程度
    type: mongoose.Types.ObjectId,
    ref: "education",
  },
  maritalid:{//婚姻情况
    type: mongoose.Types.ObjectId,
    ref: "marital",
  },
  occupation:String,//职业
  workplace:String,//工作单位
  emergency:String,//紧急联系人
  contact:String,//联系人电话
  status:Boolean,//状态
  remark:String,//备注
})
let UserListmongoose = mongoose.model("userlist", UserList, "userlist");

//民族
let nationSchema = mongoose.Schema({
  name: String, //民族名称
});
let nationModel = mongoose.model("nation", nationSchema, "nation");

// 文化程度
let educationSchema = mongoose.Schema({
  name: String, //文化程度
});
let educationModel = mongoose.model("education", educationSchema, "education");

//婚姻情况
let maritalSchema = mongoose.Schema({
  name: String, 
});
let maritalModel = mongoose.model("marital", maritalSchema, "marital");



//聊天表
// let socket_io=mongoose.Schema({
//   mid:{type:mongoose.Types.ObjectId,ref:"user"},
//   uid:{type:mongoose.Types.ObjectId,ref:"user"},
//   content:[infoSchema]
// })



//用户的聊天信息表中的info中的字段
// const infoSchema = new mongoose.Schema({
//   name: String, //发送信息的用户名字
//   img: String, //发送信息的用户头像
//   content: String, //消息内容
//   uid: { type: mongoose.Types.ObjectId, ref: 'user' }, //发送消息的用户id
//   create_time: { type: Date, default: Date.now() }, //发送时间
//   isread: { type: Boolean, default: false } //是否已读
// })

// let infoSchemaModel = mongoose.model("info", infoSchema, "info");
// ------------------------------------------------------------
//全部服务人员
let serveSchema = mongoose.Schema({
  name: String, //姓名
  id:String,
  img: String, //头像

  cateId: {
    type: mongoose.Types.ObjectId,
    ref: "cate",
  }, // 服务类型
  isselect: {
    type: Boolean,
    default: false,
  }, //是否选中状态
  phone: String, //电话
  address: String, //负责的区域
  time: {
    type: Date,
    default: Date.now,
  }, //加入的时间
  status: {
    type: Boolean,
    default: true,
  }, //状态(禁用&启用)
  register: {
    type: String,
    default: "服务器端注册",
  }, //加入方式
  tagId: {
    type: mongoose.Types.ObjectId,
    ref: "tag",
  }, //标签
  serveSum:Number,//服务工单数
});
let serveModel = mongoose.model("serve", serveSchema, "serve");

//服务类型
let cateSchema = mongoose.Schema({
  name: String, //类型名称
});
let cateModel = mongoose.model("cate", cateSchema, "cate");
//全部标签
let tagSchema = mongoose.Schema({
  name: String, //标签名称
});
let tagModel = mongoose.model("tag", tagSchema, "tag");
// ------------------------------------------------------------
//商品
//商品表
let ljyshoppingSchema = mongoose.Schema({
  title:String,
  img:String,
  uid:String,
  price:Number,
  state:Boolean,
  name:String,
  time:Date,
  cate:{
    type: mongoose.Schema.Types.ObjectId,
    ref: "Category",
  },
})
let ljyshopping= mongoose.model("ljyshopping",ljyshoppingSchema,"ljyshopping")
//商品分类
let CategorySchema = mongoose.Schema({
  title:String,
  img:String,
  number:String,
})
let Category = mongoose.model("Category",CategorySchema,"Category")
let kangSchema = mongoose.Schema({
  title:String,
  uid:String,
  price:String,
  img:String,
  time:Date,
  name:String,
  state:Boolean,
  cate:{
    type: mongoose.Schema.Types.ObjectId,
    ref: "Category",
  },
})
let kang = mongoose.model("kang",kangSchema,"kang")
//项目服务管理
let weterSchema = mongoose.Schema({
  title:String,
  img:String,
  number:String,
})
let weter = mongoose.model("weter",weterSchema,"weter")
//交易数据
let tradeSchema = mongoose.Schema({
   title:String,
   img:String,
   price:String,
   tou:String,
   name:String,
   phone:String,
   state:String,
   zhi:String,
})
let trade = mongoose.model("trade",tradeSchema,"trade")
//售后数据
let afterSchema = mongoose.Schema({
   title:String,
   img:String,
   price:String,
   price1:String,
   time:Date,
   state:String,
})
let after = mongoose.model("after",afterSchema,"after")


//--------------------------------------------------
//用户社交--zzj
let socialSchema = mongoose.Schema({
  name: String, //社交名称
  userId:Number,//Id
  img: String, //头像
  realName: String, //真实姓名
  phone:Number,//手机号码
  dynamic:Number,//动态数量
  read:Number,//阅读量
  attention:Number,//关注
  fans:Number,//粉丝
  collections:Number,//收藏
  comment:Number,//评论
  upvote:Number,//点赞
  transmit:Number,//转发
});
let socialModel = mongoose.model("social", socialSchema, "social");
module.exports = {
  userModel,
  role,
  authority,
  serveModel,
  cateModel,
  tagModel,
  UserListmongoose,
  nationModel,
  educationModel,
  maritalModel,
  ljyshopping,
  Category,
  kang,
  trade,
  weter,
  after,
  socialModel,
};
